package projetofinal.wsdl2js;

import java.io.File;

import org.apache.woden.WSDLException;
import org.apache.woden.WSDLFactory;
import org.apache.woden.WSDLReader;
import org.apache.woden.wsdl20.Description;

import projetofinal.wsdl2js.exception.ExceptionHandler;
import projetofinal.wsdl2js.js.JSFileStub;
import projetofinal.wsdl2js.util.Util;
import projetofinal.wsdl2js.wsdl.WSDLConverter;

//import projetofinal.wsdl2js.wsdl.WSDLDocument;

public final class LaunchApp {

	public static void main (String[] aStringArray) {
//		Args.checkForEmptyArray(aStringArray);
		
		//TODO tratar strings com espaço
		String wsdlPath = new String("C:\\TestesProjeto\\cep.wsdl");
		//TODO pegar o path do aStringArray[0];
//		String wsdlPath = aStringArray[0]; //Colocar no lugar da linha de cima
		String wsdlFolder = Util.getPathWithoutFilename(new File(wsdlPath)); //colocar o array no argumento denovo
		String wsdlFileName = wsdlPath.replace(wsdlFolder, "").replace(".wsdl","");
		
		WSDLConverter converter = new WSDLConverter();
		converter.convertToWSDL20(wsdlPath);
		
		wsdlPath = wsdlPath + "2";

		try {
			Description description = lerWsdl(wsdlPath);
			
			JSFileStub jsFile = new JSFileStub(wsdlFolder, wsdlFileName, description);
			jsFile.toJavaScript();
			
		} catch (WSDLException we) {
			ExceptionHandler.handle(we);
		}
		
		System.exit(0);
	}
	
	
	static Description lerWsdl(String aWsdlPath) throws WSDLException{
		WSDLFactory wsdlFactory = WSDLFactory.newInstance();
		WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
		wsdlReader.setFeature(WSDLReader.FEATURE_VALIDATION, true);
		return wsdlReader.readWSDL(aWsdlPath);
	}

	// PRIVATE //
	
}
